package com.example.fw;

import org.openqa.selenium.By;

public class NavigationHelper extends WebDriverHelperBase{

	public NavigationHelper(ApplicationManager manager) {
		super(manager);
	}

	public void mainPage() {
		
		if (! onMainPage()){
	    
	    click(By.linkText("home"));
		}
		
	  }

	private boolean onMainPage() {
	    return  (driver.findElements(By.id("maintable")).size() > 0);
	}

	public void homePage() {
		click(By.linkText("home page"));
	}

	public void contactPage() {
		if(! onContactPage()){
		click(By.linkText("add new"));
		}
	}

	private boolean onContactPage() {
		if (driver.getCurrentUrl().contains("/edit.php") 
			    && driver.findElements(By.xpath("//div[@id='content']/h1[contains(text(), 'Edit / add address book entry')]")).size() > 0){
				return true;
			}else {
				return false;
			}
	}

	public void groupsPage() {
		if(! onGroupsPage()){
	    click(By.linkText("groups"));
		}
	  }

	private boolean onGroupsPage() {
		if (driver.getCurrentUrl().contains("/group.php") 
		    && driver.findElements(By.name("new")).size() > 0){
			return true;
		}else {
			return false;
		}
		
		
	}

}
